import { http } from 'utils'

export async function getImageList({ pageSize, page, gid }) {
  const res = await http.get('image/list', { pageSize, page, gid })
  return res
}

export async function getGroupList() {
  const res = await http.get('image/groupList')
  return res
}

export async function deleteImgById(id) {
  const res = await http.get('image/list', { id })
  return res
}

export async function deleteGroup(id) {
  try {
    const res = await http.get('image/deleteGroup', { id })
    if (res.code === 1) {
      return res
    }
    throw res.info
  } catch (err) {
    throw err
  }
}

export async function addImgGroup(name) {
  try {
    const res = await http.post('image/addGroup ', { name })
    if (res.code === 1) {
      return res
    }
    throw res.info
  } catch (err) {
    throw err
  }
}

export async function imageGrouping({ id, gid }) {
  try {
    const res = await http.post('image/grouping ', { id, gid })
    if (res.code === 1) {
      return res
    }
    throw res.info
  } catch (err) {
    throw err
  }
}
